<template>
  <div class="container">
    <div class="list-title">
      <h1>{{ title }}</h1>
      <a href="">更多 ></a>
    </div>
    <!-- 渲染主打产品 -->
    <div class="product-top" v-if="canshow">
      <div class="product-top-detail" @click="goToTopUrl">
        <div class="product-pic">
          <img v-lazy="productList[0].s_goods_photos[0].path" alt="" />
          <!-- {{productList[0].s_goods_photos[1].path}} -->
        </div>
        <div class="product-text">
          <h1>{{ productList[0].name }}</h1>
          <h2>{{ productList[0].desc }}</h2>
          <h3>￥{{ productList[0].price }}</h3>
        </div>
      </div>
      <div class="video">
        <video :src="showVideoPath" autoplay loop muted width="100%"></video>
      </div>
    </div>
    <!-- 系列list -->
    <div class="product-list">
      <div
        class="product-small-box"
        v-for="item in sonList"
        :key="item.id"
        @click="goTOUrl(item.id)"
      >
        <div class="box-top">
          <img v-lazy="item.s_goods_photos[0].path" alt="" />
        </div>
        <div class="box-text">
          <h1>{{ item.name }}</h1>
          <h3>￥{{ item.price }}</h3>
        </div>
        <div class="box-mask" v-if="item.s_goods_photos.length > 1">
          <img v-lazy="item.s_goods_photos[1].path" alt="" />
          <h1>{{ item.desc }}</h1>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import { getGoods } from "@/assets/tool/request.js";
export default {
  props: {
    msg: {
      // type :Object,
      default: {},
    },
    title: {
      default: "null",
    },
    videoPath: {
      default: "null",
    },
    canshow: {
      default: true,
    },
  },
  data() {
    return {
      // 总数据
      productList: [],
      // 第一列数据
      sonList: [],
      showVideoPath: "",
    };
  },
  methods: {
    goToTopUrl() {
      this.$router.push(`/product/${this.productList[0].id}`);
    },
    goTOUrl(id) {
      this.$router.push(`/product/${id}`);
    },
  },
  async created() {
    this.productList = this.msg.data.result.rows.reverse();
    this.sonList = this.productList.slice(1, 5);
  },
  // 这里是组件复用的时候注意要重新赋值
  watch: {
    msg(newVal) {
      this.productList = newVal.data.result.rows.reverse();
      this.sonList = this.productList.slice(1, 5);
    },
  },
  mounted() {
    this.showVideoPath = this.videoPath;
    // console.log(this.showVideoPath, 222121213123123);
  },
};
</script>

<style lang="scss" scoped>
.container {
  // height: 400px;
  width: 1200px;
  margin: 40px auto 0;
  .list-title {
    width: 1200px;
    margin: 0 auto 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    h1 {
      font-size: 32px;
      font-family: Microsoft Yahei;
      text-transform: capitalize;
      font-weight: 540;
    }
    a {
      font-family: Microsoft Yahei;
      color: #000;
    }
  }
}
// 主打产品样式
.product-top {
  background-color: white;
  height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  .product-top-detail {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    &:hover {
      cursor: pointer;
    }
    .product-pic {
      width: 45%;
      img {
        width: 100%;
      }
    }
    .product-text {
      width: 40%;
      h1 {
        font-family: Microsoft JhengHei;
        font-size: 24px;
        font-weight: 600;
        line-height: 32px;
        margin-bottom: 16px;
      }
      h2 {
        font-size: 14px;
        line-height: 24px;
        margin-bottom: 24px;
      }
      h3 {
        font-size: 16px;
        line-height: 20px;
        margin-bottom: 24px;
      }
    }
  }
  .video {
    flex: 1;
    video {
      width: 100%;
    }
  }
}

// 小产品
.product-list {
  margin-top: 15px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .product-small-box {
    position: relative;
    background-color: white;
    width: 24%;
    height: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    &:hover {
      cursor: pointer;
      .box-mask {
        opacity: 1;
      }
    }
    .box-top {
      flex: 2;
      text-align: center;
      line-height: 300px;
      img {
        width: 90%;
      }
    }
    .box-text {
      flex: 1;
      h1 {
        text-align: center;
        height: 48px;
        margin: 15px 0;
        font-size: 18px;
        font-family: Microsoft Yahei;
        text-transform: capitalize;
      }
      h3 {
        text-align: center;
        font-size: 14px;
        font-family: Microsoft Yahei;
        text-transform: capitalize;
      }
    }
    .box-mask {
      position: absolute;
      width: 100%;
      opacity: 0;
      transition: all 0.3s;
      img {
        width: 100%;
      }
      h1 {
        box-sizing: border-box;
        width: 100%;
        position: absolute;
        bottom: 0;
        text-align: center;
        font-size: 14px;
        // font-family: Microsoft Yahei;
        text-transform: capitalize;
        padding: 2% 8%;
        color: #fff;
        letter-spacing: normal;
        line-height: 18px;
        background-color: rgba(59, 62, 64, 0.45);
      }
    }
  }
}
</style>